<template>
	<view style="width: 100%;">
		<view>
			<uni-nav-bar right-icon="scan" background-color="#1E90FF" fixed="true" shadow="flase" @clickRight="faceRegister"><text class="txt">扫码查询</text></uni-nav-bar>
		</view>

		<view style="margin-top: 5%;">
			<uni-list>
				<uni-list-item :title="data.name" v-for="(data,index) in listContent" @click="detail(data.id,data.index)" :key="index" />
			</uni-list>
		</view>
	</view>
</template>

<script>
	import uniList from '@/components/uni-list/uni-list.vue';
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
	import uniIcons from '@dcloudio/uni-ui/lib/uni-icons/uni-icons.vue';
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	import {
		mapState
	} from 'vuex'
	import loginjs from '../../login.js'
	export default {
		computed: mapState(['baseUrl']),
		components: {
			uniList,
			uniListItem,
			uniIcons,
			uniNavBar
		},
		data() {
			return {
				listContent: [],
				billQuarantine: {
					"id": null,
					"decId": null,
					workId: null,
					"assId": null,
					"samplNoticeId": null,
					"workId": null,
					"qualificationAId": null,
					"qualificationBId": null
				}
			}
		},

		onLoad() {
			//检测用户是否登录
			var uNameAndAuth = loginjs.checkLogin();
			//用户名和认证信息的组合
			uNameAndAuth = uNameAndAuth.split('/');
			this.user = uNameAndAuth[0];
			this.Authorization = uNameAndAuth[1];
			if (this.Authorization == null) {
				return;
			}
		},
		methods: {
			faceRegister() {
				// 允许从相机和相册扫码
				var _this = this
				uni.scanCode({
					success: function(res) {
						_this.getQuarantineList(res.result)
					}
				});
			},
			getQuarantineList(val) {
				this.listContent = []
				uni.request({
					method: "GET",
					url: this.baseUrl + 'api/quarantine/tenement/' + val,
					header: {
						"Authorization": this.Authorization,
					},
					success: (res) => {
						this.billQuarantine = res.data.data
						console.log(this.billQuarantine)
						if(this.billQuarantine==null){
							return
						}
						if (this.billQuarantine.decId != null) {
							this.listContent.push({
								index: 1,
								name: '检疫申报/受理单',
								id: this.billQuarantine.decId
							})
						}
						if (this.billQuarantine.workId != null) {
							this.listContent.push({
								index: 2,
								name: '水产苗种产地检疫工作记录单',
								id: this.billQuarantine.workId
							})
						}
						if (this.billQuarantine.assId != null) {
							this.listContent.push({
								index: 3,
								name: '协助临床检查情况说明',
								id: this.billQuarantine.assId
							})
						}
						if (this.billQuarantine.samplNoticeId != null) {
							this.listContent.push({
								index: 4,
								name: '水产苗种产地检疫采样送检通知单',
								id: this.billQuarantine.samplNoticeId
							})
						}
						if (this.billQuarantine.qualificationAId != null) {
							this.listContent.push({
								index: 5,
								name: '动物检疫合格证明（动物A）',
								id: this.billQuarantine.qualificationAId
							})
						}

						if (this.billQuarantine.qualificationBId != null) {
							this.listContent.push({
								index: 6,
								name: '动物检疫合格证明（动物B）',
								id: this.billQuarantine.qualificationBId
							})
						}
						
					},
					fail() {
						uni.showToast({
							title: "获取网络数据失败",
							icon: "none",
							duration: 1000
						})
					}

				})
			},
			detail(id, index) {
				console.log(id, index)
				var url = ''
				if (index == 1) {
					url = './page/declare?id=' + id
				}
				if (index == 2) {
					url = './page/work?id=' + id
				}
				if (index == 3) {
					url = './page/assist?id=' + id
				}
				if (index == 4) {
					url = './page/inspection?id=' + id
				}
				if (index == 5) {
					url = './page/qualificationA?id=' + id
				}
				if (index == 6) {
					url = './page/qualificationB?id=' + id
				}
				uni.navigateTo({
					url: url
				});
			}
		}
	};
</script>

<style scoped>
.txt {
		/* font-weight: 700; */
	    font-size: 16px;
	    line-height: 30px;
	    overflow: hidden;
	    white-space: nowrap;
	    text-overflow: ellipsis;
		position: absolute;
		left: 50%;
		margin-left: -32px;
}

</style>
